﻿Imports System.Xml
Imports System.EventArgs
Imports System.Data.OleDb

Public Class test
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "application/rss+xml"
        Response.ContentEncoding = Encoding.UTF8
        Dim rssW As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        rssOpen(rssW)
        Dim researchExplorer As DataTable = getDatafrom()
        rssBody(rssW, researchExplorer)
        rssClose(rssW)
        rssW.Flush()
        Response.End()

    End Sub

    Private Sub rssOpen(ByVal rssW As XmlTextWriter)
        rssW.WriteStartElement("rss")
        rssW.WriteStartElement("version", "2.0")
        rssW.WriteStartElement("channel")
        rssW.WriteStartElement("title", "Ad Hoc Researches")
        rssW.WriteStartElement("link", "ResearchList.aspx")
        rssW.WriteStartElement("description", "Ad Hoc Networking Papers")
    End Sub

    Private Sub rssBody(ByVal rssW As XmlTextWriter, ByVal data As DataTable)
        For Each researchField As DataRow In data.Rows
            rssW.WriteStartElement("item")
            rssW.WriteStartElement("title", researchField(1).ToString)
            rssW.WriteStartElement("link", "ResearchListDetails.aspx?ID=" & researchField(0).ToString)
            rssW.WriteStartElement("description", "Research Description" & researchField(6).ToString)
            rssW.WriteEndElement()
        Next

    End Sub

    Private Sub rssClose(ByVal rssW As XmlTextWriter)
        rssW.WriteEndElement()
        rssW.WriteEndElement()
    End Sub

    Private Function getDatafrom()
        Dim researchT = New DataTable()
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = New String("SELECT * FROM [Researches]")
        Dim oleAdapt = New OleDbDataAdapter(sql, conn)
        oleAdapt.Fill(researchT)
        Return researchT
    End Function
End Class